<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Customising Web Runner</title>
</head>

<body>

<h2>Configuring Steps in the Web Runner</h2>

<p>The Web Runner is a webapp that allows users to run any generic
textual story. In order to do this, the appropriate JBehave Steps
instances required to match the textual steps need to be configured in
the application.</p>

<p>The Web Runner is a Wicket-based application and provides a base application class, <a
    href="https://github.com/jbehave/jbehave-web/blob/master/web-runner/src/main/java/org/jbehave/web/runner/wicket/WebRunnerApplication.java">WebRunnerApplication</a>
which only requires the specification of the InjectableStepsFactory for the
story running, e.g.:</p>
<script type="syntaxhighlighter" class="brush: java">
<![CDATA[
public class TraderRunnerApplication extends WebRunnerApplication {

    protected InjectableStepsFactory stepsFactory() {
        return new InstanceStepsFactory(configuration(), new TraderSteps(new TradingService()),
                new StockExchangeSteps());
    }

}
]]>
</script>
<p>The user can optionaly override any of the protected methods of <a
    href="https://github.com/jbehave/jbehave-web/blob/master/web-runner/src/main/java/org/jbehave/web/runner/wicket/WebRunnerApplication.java">WebRunnerApplication</a>
which return instances of the configurable components of the Web Runner.</p>

<p>The application class name then needs to be configured in the <b>WicketFilter</b> in your <b>web.xml</b>:</p>

<script type="syntaxhighlighter" class="brush: xml">
<![CDATA[
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5">

  <display-name>JBehave Web Runner</display-name>
  <filter>
    <filter-name>application</filter-name>
    <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class>
    <init-param>
      <param-name>applicationClassName</param-name>
      <param-value>org.jbehave.web.examples.trader.runner.TraderRunnerApplication</param-value>
    </init-param>
    <init-param>
      <!-- Use system property "wicket.configuration" to override to "development" when needed -->
      <param-name>configuration</param-name>
      <param-value>deployment</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>application</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
  </filter-mapping>

</web-app>
]]>
</script>

<p>Note that some webapp containers may not handle filters properly.  In this case, you can equally use a servlet to configure
 the Wicket application:</p>

<![CDATA[
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  version="2.5">

  <display-name>JBehave Web Runner</display-name>

  <servlet>
    <servlet-name>wicket</servlet-name>
    <servlet-class>org.apache.wicket.protocol.http.WicketServlet</servlet-class>
    <init-param>
      <param-name>applicationClassName</param-name>
      <param-value>org.jbehave.web.examples.trader.runner.TraderRunnerApplication</param-value>
    </init-param>
    <init-param>
      <!-- Use system property "wicket.configuration" to override to "development" when needed -->
      <param-name>configuration</param-name>
      <param-value>deployment</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>wicket</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>

</web-app>
]]>
</script>

<h2>Running with Maven</h2>

<p>Maven users can model their own module on the <a
    href="https://github.com/jbehave/jbehave-web/blob/master/examples/trader-runner">trader
runner example</a></p>

<h2>Running with Ant</h2>

<p>Ant users can download the web distribution from <a
    href="download.html">download page</a></p>

<ul>
    <li>Unzip it to a local directory</li>
    <li>Add a jar containing your Steps and Wicket application instances to
    lib/ directory</li>
    <li>Edit <b>webapp/WEB-INF/web.xml</b> to configure the
    Application class name that you've defined, replacing the <b>org.jbehave.web.runner.wicket.WebRunnerApplication</b>
    class name with your fully-qualified Application class name. See <a
        href="https://github.com/jbehave/jbehave-web/blob/master/examples/trader-runner/src/main/java/org/jbehave/web/examples/trader/runner/TraderRunnerApplication.java">TraderRunnerApplication</a>
    for an example of how easy it is. The minimal requirement is to
    specify the one or more instances of Steps that you need to run the
    stories.</li>
    <li>In <b>bin/</b> dir execute: <b>ant -f deploy.xml
    deploy:webapp</b>, which will deploy a new jbehave-web.war to your local
    Jetty installation (provided you have <b>$JETTY_HOME</b> defined).
    You can configure your own deploy dir via the <b>deploy.properties</b>
    file or simply copy the war created in the target/ dir to your
    favourite webapp container.</li>
</ul>

<h2>Customising the Web Runner resources</h2>

<p>The Web Runner comes with default web resources, but these can be
overridden by adding them to the <b>src/main/webapp</b> directory. Only
custom resources that override the default ones are required. So, e.g.
to change the default style, only <b>src/main/webapp/style/jbehave/jbehave.css</b>
needs to be added.</p>

</body>
</html>